/*
package com.xcc.common.utils;

import com.xcc.common.domain.entry.User;
import org.apache.poi.hssf.record.formula.functions.T;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.w3c.dom.ls.LSException;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;

*/
/**
 * @author frosty
 * @description
 * @date 2019-11-28 28:15:16
 *//*



public class ExclUtil {


    public static void main(String[] args) throws Exception {
              String sheName="my.xls";
        //excel标题
         String[] title = {"编号","code","用户名","密码","状态"};
        String [] prop={"id","userCode","userName","password","state"};
        File file=new File("/home/swst/my.xls");
        if(!file.exists()){
            file.createNewFile();
        }

        FileInputStream fis=new FileInputStream(file);
        HSSFWorkbook wb=null;
try{
    POIFSFileSystem ps=new POIFSFileSystem(fis);  //使用POI提供的方法得到excel的信息
     wb=new HSSFWorkbook(ps);
}catch (Exception e){
     wb=new HSSFWorkbook();
}



//   HSSFSheet sheet=wb.getSheetAt(0);


        List<User> list = new ArrayList<>();
        User u;
        u=new User();
        u.setId("12454");

        list.add(u);
        u=new User();
        u.setId("12");
        list.add(u);
        u=new User();
        u.setId("13");
        list.add(u);
         List<Map<String, Object>> maps = listBean2ListMap(list);



        HSSFWorkbook hssfWorkbook = getHSSFWorkbook(sheName, title, maps, prop,wb);

        FileOutputStream fot=new FileOutputStream(file);
        hssfWorkbook.write(fot);


    }






    */
/**
     * 导出Excel
     *
     * @param sheetName sheet名称
     * @param title     标题
     * @param list    内容
     * @param wb        HSSFWorkbook对象
     * @return
     *//*

    public static HSSFWorkbook getHSSFWorkbook(String sheetName, String[] title, List<Map<String,Object>> list, String []prop,HSSFWorkbook wb) {


        // 第一步，创建一个HSSFWorkbook，对应一个Excel文件
        if (wb == null) {
            wb = new HSSFWorkbook();
        }

        int start=0;
        HSSFSheet sheet;
        try {

            sheet = wb.getSheetAt(0);
            start=sheet.getLastRowNum();
        }catch (Exception e){
            sheet=wb.createSheet(sheetName);
        }


        // 第二步，在workbook中添加一个sheet,对应Excel文件中的sheet





        // 第三步，在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制
        HSSFRow row = sheet.createRow(0);

        // 第四步，创建单元格，并设置值表头 设置表头居中
        HSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式

        //声明列对象
        HSSFCell cell = null;

        //创建标题
        for (int i = 0; i < title.length; i++) {
            cell = row.createCell(i);
            cell.setCellValue(title[i]);
            cell.setCellStyle(style);
        }

        //创建内容
        for (int i = start; i < start+list.size(); i++) {
            row = sheet.createRow(i + 1);
            for (int j = 0; j < title.length; j++) {
                //将内容按顺序赋给对应的列对象
                try {
                    row.createCell(j).setCellValue((String) list.get(i-start).get(prop[j]));

                }catch (Exception e ){
                    e.printStackTrace();
                }
            }
        }
        return wb;
    }


    public static <E> void exportExcl(List<E> list) throws Exception {



    }


    */
/**
     * bean  转map
     *
     * @param bean
     * @param <T>
     * @param <K>
     * @param <V>
     * @return
     * @throws Exception
     * @throws IllegalAccessException
     *//*


    public static <T, K, V> Map<String, Object> bean2Map(T bean)
            throws Exception, IllegalAccessException {

        if (bean == null) {
            return null;
        }

        Map<String, Object> mp = new HashMap<>();

        try {
            BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass());
            PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();

            for (PropertyDescriptor property : propertyDescriptors) {
                String key = property.getName();

                if (!key.equals("class")) {

                    Method getter = property.getReadMethod();// Java中提供了用来访问某个属性的
                    // getter/setter方法
                    Object value;

                    value = getter.invoke(bean);
                    mp.put(key, value);
                }

            }

        } catch (IntrospectionException e) {

            e.printStackTrace();
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

        }
        return mp;

    }


    */
/**
     * 将一个list对象转为listMap
     *
     * @param list
     * @param <E>
     * @return
     * @throws Exception
     *//*

    public static  <E> List<Map<String, Object>> listBean2ListMap(List<E> list) throws Exception {
        if (list == null || list.size() == 0) {
            return null;
        }
        List<Map<String, Object>> listMap = new ArrayList<>();

        for (int i = 0; i < list.size(); i++) {
            listMap.add(bean2Map(list.get(i)));
        }
        return listMap;
     }
}







*/
